//
//  RCTrainCell.m
//  RocketProject
//
//  Created by chen jiedan on 13-9-7.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCTrainCell.h"
#import "CommonDefines.h"
#import "UIColor-Expanded.h"

#define kLineImageFile          @"image_line_type3.png"
#define kBGImageFile            @"image_discount_cell_bg.png"
#define kArrowImageFile         @"flyTicket_orderCell_arrow.png"

@implementation RCTrainCell{
    UILabel *_startTime;
    UILabel *_endTime;
    UILabel *_trainNumber;

    UILabel *_startAddr;
    UILabel *_endAddr;
    
    UILabel *_costTimeLabel;
    UILabel *_price;
    UILabel *_levelLabel;
    
    UIImageView *_arrowImageView;
    UIImageView *_lineImageView;
    
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        UIImage *bgImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kBGImageFile ofType:nil]];
        [self setBackgroundColorWithImage:bgImage];
        self.backgroundColor = [UIColor clearColor];
        
        [self createPlaceHolder];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (void) createPlaceHolder
{
    _startTime = [[UILabel alloc] initWithFrame:CGRectMake(15, 25, 55, 15)];
    _startTime.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    _startTime.backgroundColor = [UIColor clearColor];
    _startTime.textColor = [UIColor colorWithRed:10.0/255 green:96.0/255 blue:180.0/255 alpha:1];
    [self.contentView addSubview:_startTime];
    [_startTime release];
    
    
    _endTime = [[UILabel alloc] initWithFrame:CGRectMake(15, 45, 40, 12)];
    _endTime.font = [UIFont fontWithName:kFontNameHelvetica size:12];
    _endTime.backgroundColor = [UIColor clearColor];
    _endTime.textColor = _startTime.textColor;
    [self.contentView addSubview:_endTime];
    [_endTime release];
    
    
    _trainNumber = [[UILabel alloc] initWithFrame:CGRectMake(85, 15, 200, 15)];
    _trainNumber.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    _trainNumber.backgroundColor = [UIColor clearColor];
    _trainNumber.textColor = kNormalHeadTextColor;
    [self.contentView addSubview:_trainNumber];
    [_trainNumber release];
    
    
    UIImageView *startAddIMG = [[UIImageView alloc] initWithFrame:CGRectMake(80, 38, 12, 12)];
    startAddIMG.image = [UIImage imageNamed:@"icon_train_startAddr"];
    [self.contentView addSubview:startAddIMG];
    [startAddIMG release];
    
    _startAddr = [[UILabel alloc] initWithFrame:CGRectMake(100, 35, 80, 15)];
    _startAddr.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    _startAddr.backgroundColor = [UIColor clearColor];
    _startAddr.textColor = kNormalTextColor;
    [self.contentView addSubview:_startAddr];
    [_startAddr release];
    
    
    UIImageView *endAddIMG = [[UIImageView alloc] initWithFrame:CGRectMake(80, 57, 12, 12)];
    endAddIMG.image = [UIImage imageNamed:@"icon_train_endAddr"];
    [self.contentView addSubview:endAddIMG];
    [endAddIMG release];
    
    _endAddr = [[UILabel alloc] initWithFrame:CGRectMake(100, 55, 80, 15)];
    _endAddr.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    _endAddr.backgroundColor = [UIColor clearColor];
    _endAddr.textColor = kNormalTextColor;
    [self.contentView addSubview:_endAddr];
    [_endAddr release];
    
    
    _costTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(175, 40, 100, 15)];
    _costTimeLabel.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    _costTimeLabel.backgroundColor = [UIColor clearColor];
    _costTimeLabel.textColor = kNormalHeadTextColor;
    [self.contentView addSubview:_costTimeLabel];
    [_costTimeLabel release];
    
    
    _price = [[UILabel alloc] initWithFrame:CGRectMake(240, 25, 60, 15)];
    _price.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    _price.backgroundColor = [UIColor clearColor];
    _price.textColor = [UIColor colorWithRed:1 green:142.0/255 blue:48.0/255 alpha:1];

    [self.contentView addSubview:_price];
    [_price release];
    
    
    
    _levelLabel = [[UILabel alloc] initWithFrame:CGRectMake(240, 50, 50, 14)];
    _levelLabel.font = [UIFont fontWithName:kFontNameHelvetica size:12];
    _levelLabel.backgroundColor = [UIColor clearColor];
    _levelLabel.textColor = kNormalHeadTextColor;

    [self.contentView addSubview:_levelLabel];
    [_levelLabel release];
    
    _arrowImageView = [[UIImageView alloc]initWithFrame:CGRectMake(296, 36, 10, 12)];
    _arrowImageView.backgroundColor = [UIColor clearColor];
    [_arrowImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kArrowImageFile ofType:nil]]];
    [self.contentView addSubview:_arrowImageView];
    [_arrowImageView release];
    
    _lineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 84, 320, 1)];
    _lineImageView.backgroundColor = [UIColor clearColor];
    [_lineImageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:kLineImageFile ofType:nil]]];
    [self.contentView addSubview:_lineImageView];
    [_lineImageView release];
    
}

- (void) bindData:(RCTrainItemDataModel *)model
{
    _startTime.text = model.starttime;
    _endTime.text = model.endtime;
    _trainNumber.text = [NSString stringWithFormat:@"%@-%@",model.trainname,model.traincode];

    _startAddr.text = model.startcity;
    _endAddr.text = model.endcity;
    _costTimeLabel.text = model.coattime;
    
    _price.text = [NSString stringWithFormat:@"￥%@",model.ticketprice];;
    _levelLabel.text = model.ticketname;
    
}

@end

